using UnityEngine;

namespace LS.SimpleInput
{
    public abstract class PointInputer : Inputer
    {
        public abstract Vector2 StartPoint { get; }
        public abstract Vector2 Point { get; }
        public abstract Vector2 DeltaPoint { get; }
        public abstract bool EventSystemDetected { get; }

        public PointInputer(UserInputSetting setting) : base(setting)
        {
            m_Setting = setting;
        }

        public PointInputer() : this(null)
        {

        }

        public override Gesture CreateGesture()
        {
            Gesture ges = base.CreateGesture();
            ges.eventSystemDetected = EventSystemDetected;
            ges.startPoint = StartPoint;
            ges.point = Point;
            ges.deltaPoint = DeltaPoint;
            if(Phase == InputPhase.Moved)
            {
                ges.moveDirection = GestureStateUtility.GetDirection(Vector2.zero, DeltaPoint, Setting.movementDirectionTolerance);
            }
            else if (Phase == InputPhase.Ended || Phase == InputPhase.Canceled)
            {
                ges.moveDirection = GestureStateUtility.GetDirection(StartPoint, Point, Setting.movementDirectionTolerance);
            }
            return ges;
        }
    }
}
